Skip to content

fix(mcp): tolerate invalid tool output schemas#26530

Closed
nicolascancino wants to merge 4 commits into
anomalyco:devfrom
nicolascancino:fix/mcp-output-schema-ref
Closed

fix(mcp): tolerate invalid tool output schemas#26530
nicolascancino wants to merge 4 commits into
anomalyco:devfrom
nicolascancino:fix/mcp-output-schema-ref

Conversation

@nicolascancino
Copy link
Copy Markdown

Issue for this PR

Closes #26529

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Makes MCP tool loading resilient when a server returns a valid tools/list response whose outputSchema contains refs the SDK cannot resolve.

The normal client.listTools() path still runs first. If it fails with a schema reference error, OpenCode retries tools/list with a tolerant result schema that keeps inputSchema validation and treats outputSchema as opaque.

This fixes Google Stitch-style failures where the MCP transport connects but OpenCode marks the server as failed while validating tool output schemas.

How did you verify your code works?

cd packages/opencode
bun test test/mcp/lifecycle.test.ts --timeout 30000

Result:

20 pass
0 fail
51 expect() calls
Ran 20 tests across 1 file. [2.13s]

Screenshots / recordings

N/A — non-UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@kitlangton
Copy link
Copy Markdown
Contributor

Thanks for putting this fix together. I opened #26614 based on this approach, rebased onto current dev, with a narrower fallback and additional regression coverage for both the Stitch-style schema-ref failure and the non-schema failure path.

Closing this one in favor of #26614 so we have a clean branch for merge. Credit to @nicolascancino for the original fix direction here.

@kitlangton kitlangton closed this May 10, 2026
auto-merge was automatically disabled May 10, 2026 01:20

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP tools fail to load when outputSchema contains unresolved refs

2 participants